package com.onejson.ojmall.controller;


import com.onejson.ojmall.common.domain.PageResult;
import com.onejson.ojmall.common.apiencrypt.domain.ValidateList;
import com.onejson.ojmall.common.domain.ResponseDTO;
import com.onejson.ojmall.model.form.SMenuBatchForm;
import com.onejson.ojmall.model.form.SMenuForm;
import com.onejson.ojmall.model.form.SMenuQueryForm;
import com.onejson.ojmall.model.vo.SMenuVO;
import com.onejson.ojmall.service.SMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 菜单表控制器
 *
 * @author wxx
 */
@Slf4j
@RestController
@Tag(name = "菜单表")
//@OperateLog
public class SMenuController {


    //【菜单表】Service层

    @Resource
    private SMenuService sMenuService;


    @Operation(summary = "【菜单表】 - 查询")
    @PostMapping("/zichan/sMenu/queryPage")
    public ResponseDTO<PageResult<SMenuVO>> querySMenu(@RequestBody @Valid SMenuQueryForm queryForm) {
        return ResponseDTO.ok(sMenuService.getList(queryForm));
    }

    @Operation(summary = " 【菜单表】 - 详情")
    @GetMapping("/zichan/sMenu//{detailId}")
    public ResponseDTO<SMenuVO> getInfo(@PathVariable("detailId") String detailId) {
        return ResponseDTO.ok(sMenuService.queryById(detailId));
    }

    @Operation(summary = " 【菜单表】 - 添加")
    @PostMapping("/zichan/sMenu/add")
    public ResponseDTO<String> addSMenu(@RequestBody @Valid SMenuForm addForm) {
        return sMenuService.addSMenu(addForm);
    }

    @Operation(summary = "【菜单表】 - 更新")
    @PostMapping("/zichan/sMenu/update")
    public ResponseDTO<String> updateSMenu(@RequestBody @Valid SMenuForm updateForm) {
        return sMenuService.updateSMenu(updateForm);
    }

    @Operation(summary = "【菜单表】 - 批量更新")
    @PostMapping("/zichan/sMenu/batchUpdate")
    public ResponseDTO<String> batchUpdateSMenu(@RequestBody @Valid SMenuBatchForm sMenuBatchForm) {
        return sMenuService.batchUpdateSMenu(sMenuBatchForm);
    }

    @Operation(summary = "【菜单表】 - 批量删除")
    @PostMapping("/zichan/sMenu/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<String> idList) {
        return sMenuService.batchDelete(idList);
    }

    @Operation(summary = "【菜单表】 - 单个删除")
    @GetMapping("/zichan/SMenu/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable String id) {
        return sMenuService.delete(id);
    }

}

